﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VirtualPress.Infrastructure.Entities.Entity;
using VirtualPress.Portal.Biz;
using VirtualPress.Infrastructure.Entities.Enum;
using VirtualPress.Tool.Configration;

namespace VirtualPress.Portal.Web.Controllers
{
    public class ConferenceController : Controller
    {
        public ActionResult About(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}",SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
        public ActionResult Home(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            List<News> list = iCache.Get(
                String.Format("CommonBiz.GetAllNews_Meeting_{0}_{1}_{2}",
                id.ToString(), 0, 20), () => { return CommonBiz.GetAllNews(NewsType.MeetingNews, id, OrganizationType.Meeting, 0, 20); }, 600);
            ViewBag.News = list;

            List<ImportantPan> pan = iCache.Get(
                String.Format("CommonBiz.GetPan_Meeting_{0}_{1}_{2}",
                id.ToString(), 0, 20), () => { return CommonBiz.GetPan(OrganizationType.Meeting, id, 0, 20); }, 600);
            ViewBag.Pan = pan;
            return View();
        }

        public ActionResult committee(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
        public ActionResult callforpapers(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
        public ActionResult Attention(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
        public ActionResult Travel(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
        public ActionResult catalog(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
        public ActionResult schedule(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
        public ActionResult news(int id,int page=0)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            List<News> list = CommonBiz.GetAllNews( NewsType.MeetingNews, meeting.Id, OrganizationType.Meeting,
                0, 25) ;
            ItemListBox<News> data = new ItemListBox<News>(list).BuildPage(
                CommonBiz.GetAllNewsForPage(meeting.Id, OrganizationType.Meeting, NewsType.MeetingNews),
                page, 25, new PageParameter() { Style = "home" });
            ViewBag.News = data;
            return View();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type">类型ID: 1:新闻</param>
        /// <param name="sid">分类id</param>
        /// <returns></returns>
        public ActionResult Detail(int id, int type, int sid=0)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            switch (type)
            { 
                case 1:
                    News news = new News().Find(sid.ToString());
                    if (news.OrgId != id)
                    {
                        return Redirect("/news");
                    }
                    ViewBag.Title = news.Title;
                    ViewBag.SubTitle = "News";
                    ViewBag.Content = news.Content;
                    break;
            }
            return View();
        }

        public ActionResult aboutus(int id)
        {
            Meeting meeting = new Meeting().Find(id.ToString());
            if (meeting == null)
            {
                return Redirect(String.Format("http://{0}", SiteResource.Domain));
            }
            ViewBag.Meeting = meeting;
            return View();
        }
    }
}
